package com.banmao.mall.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

public class CustomUtils {

    // 判断用户是否登陆
    // 返回userId或者报出异常
    public static Integer judgeUserLogin() throws IllegalAccessException {
        // 获取当前用户信息
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        // 获取session中的用户ID
        Integer userId = (Integer) session.getAttribute("userId");

        if(userId == null) {
            throw new IllegalAccessException("该用户未登录");
        }
        return userId;
    }

}
